package com.szq.lottery.domain.strategy.service.alogorithm.impl;

import com.szq.lottery.domain.strategy.service.alogorithm.BaseAlgorithm;
import org.springframework.stereotype.Component;

import java.security.SecureRandom;
import java.util.List;

/**
 * 单项概率，奖品抽空后，概率不变
 * @author 吾空白
 */

@Component("singleRateRandomDrawAlgorithm")
public class SingleRateRandomDrawAlgorithm extends BaseAlgorithm {

    @Override
    public String randomDraw(Long strategyId, List<String> excludeAwardIds) {

        //获取策略对应的元祖
        String[] rateTuple = super.rateTupleMap.get(strategyId);
        assert rateTuple!=null;

        //随机索引
        int randomVal = new SecureRandom().nextInt(100) + 1;
        int idx=super.hasdIdx(randomVal);

        //返回结果
        String award = rateTuple[idx];
        if (excludeAwardIds.contains(award)) {
            return null;
        }

        return award;

    }
}
